/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pnf_listStaff.java
 *
 * Created on Aug 13, 2010, 7:28:29 AM
 */

package GUI;

import config.Database_function;
import config.Function;
import config.User_function;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author RYUDO
 */
public class pnf_listStaff extends javax.swing.JPanel {
     Connection cn;
     Vector tableTitle;
     Vector tableData;
     String role = "Administrator";
     String username;
    /** Creates new form pnf_listStaff */
    public pnf_listStaff() {}
    
    public pnf_listStaff(String username) {
        initComponents();
        this.username = username;
        this.pnAdvanceSearch.setVisible(false);
        this.initTableAdmin();
    }

    private void initTableAdmin() {
        tableTitle = new Vector();
        tableData = new Vector();
        try {
            cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT AdminID,Username,Firstname,Lastname,Phone,Email,Gender FROM tbl_Admin");
            ResultSetMetaData rsmd = rs.getMetaData();
            for(int i = 1;i<=rsmd.getColumnCount();i++) {
                tableTitle.add(rsmd.getColumnName(i));
            }
            while(rs.next()) {
                Vector temp = new Vector();
                 for(int i = 1;i<=rsmd.getColumnCount();i++) {
                    if(i == 7) {
                        temp.add(temp.add(Function.get_gender(rs.getString(i))));
                    } else {
                    temp.add(rs.getString(i));
                    }

                }
                tableData.add(temp);
            }
            this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));
            
        } catch (SQLException ex) {
            Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void initTableStaff() {
        tableTitle = new Vector();
        tableData = new Vector();
        try {
            cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT StaffID,username,Firstname,Lastname,Phone,Email,Gender FROM tbl_Staff");
            ResultSetMetaData rsmd = rs.getMetaData();
            for(int i = 1;i<=rsmd.getColumnCount();i++) {
                tableTitle.add(rsmd.getColumnName(i));
            }
            while(rs.next()) {
                Vector temp = new Vector();
                for(int i = 1;i<=rsmd.getColumnCount();i++) {
                    if(i == 7) {
                        temp.add(temp.add(Function.get_gender(rs.getString(i))));
                    } else {
                    temp.add(rs.getString(i));
                    }

                }
                tableData.add(temp);
            }
            this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));

        } catch (SQLException ex) {
            Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    public void search_admin() {
         tableData = new Vector();
         this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));
        try {
            Connection cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT AdminID,username,Firstname,Lastname,Phone,Email,Gender FROM tbl_Admin WHERE "+this.comSearch.getSelectedItem().toString()+" LIKE '%"+this.txtSearch.getText()+"%'");
            if(!rs.first()) {
                JOptionPane.showMessageDialog(null, "Sorry, no result");
            } else {
                rs.first();
                Vector temp = new Vector();
                temp.add(rs.getString(1));
                temp.add(rs.getString(2));
                temp.add(rs.getString(3));
                temp.add(rs.getString(4));
                temp.add(rs.getString(5));
                temp.add(rs.getString(6));
                temp.add(Function.get_gender(rs.getString(7)));
                tableData.add(temp);
                while(rs.next()) {
                    temp = new Vector();
                    temp.add(rs.getString(1));
                    temp.add(rs.getString(2));
                    temp.add(rs.getString(3));
                    temp.add(rs.getString(4));
                    temp.add(rs.getString(5));
                    temp.add(rs.getString(6));
                    temp.add(Function.get_gender(rs.getString(7)));
                            System.out.println(Function.get_gender(rs.getString(7)));
                    tableData.add(temp);
                }
                this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));

            }
        } catch (SQLException ex) {
            Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void search_staff() {
         tableData = new Vector();
         this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));
        try {
            Connection cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT StaffID,username,Firstname,Lastname,Phone,Email,Gender FROM tbl_Staff WHERE "+this.comSearch.getSelectedItem().toString()+" LIKE '%"+this.txtSearch.getText()+"%'");
            if(!rs.first()) {
                JOptionPane.showMessageDialog(null, "Sorry, no result");
            } else {
                rs.first();
                Vector temp = new Vector();
                temp.add(rs.getString(1));
                temp.add(rs.getString(2));
                temp.add(rs.getString(3));
                temp.add(rs.getString(4));
                temp.add(rs.getString(5));
                temp.add(rs.getString(6));
                temp.add(Function.get_gender(rs.getString(7)));
                tableData.add(temp);
                while(rs.next()) {
                    temp = new Vector();
                    temp.add(rs.getString(1));
                    temp.add(rs.getString(2));
                    temp.add(rs.getString(3));
                    temp.add(rs.getString(4));
                    temp.add(rs.getString(5));
                    temp.add(rs.getString(6));
                    temp.add(Function.get_gender(rs.getString(7)));
                    tableData.add(temp);
                }
                this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));
            }
        } catch (SQLException ex) {
            Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void advanceSearchAdmin(){
          tableData = new Vector();
          this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));
          String gender = "%";
          String Firstname = "";
          String Lastname = "";
          String SearchKeyword = "%";
          
             if(!this.comGender.getSelectedItem().toString().equals("Both")) {
            gender = Function.set_gender(this.comGender.getSelectedItem().toString());
          } if(this.chkFirstname.isSelected()) {
              Firstname = this.txtSearch.getText()+"%";
          } if(this.chkLastname.isSelected()) {
              Lastname = this.txtSearch.getText()+"%";
          } if(!this.txtSearch.getText().equals("")) {
              SearchKeyword = this.txtSearch.getText();
          }
        try {
            Connection cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT AdminID,username,Firstname,Lastname,Phone,Email,Gender FROM tbl_Admin WHERE "+this.comSearch.getSelectedItem().toString()+" LIKE '%"+SearchKeyword+"%'"
                    + " OR Firstname LIKE '"+Firstname+"'"
                    + " OR Lastname LIKE '"+Lastname+"'"
                    + " AND Gender LIKE '"+gender+"'");
            if(!rs.first()) {
                JOptionPane.showMessageDialog(null, "Sorry, no result");
            }else {
                rs.first();
                Vector temp = new Vector();
                temp.add(rs.getString(1));
                temp.add(rs.getString(2));
                temp.add(rs.getString(3));
                temp.add(rs.getString(4));
                temp.add(rs.getString(5));
                temp.add(rs.getString(6));
                temp.add(Function.get_gender(rs.getString(7)));
                tableData.add(temp);
                while(rs.next()) {
                    temp = new Vector();
                    temp.add(rs.getString(1));
                    temp.add(rs.getString(2));
                    temp.add(rs.getString(3));
                    temp.add(rs.getString(4));
                    temp.add(rs.getString(5));
                    temp.add(rs.getString(6));
                    temp.add(Function.get_gender(rs.getString(7)));
                            System.out.println(Function.get_gender(rs.getString(7)));
                    tableData.add(temp);
                }
                this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));

            }
        } catch (SQLException ex) {
            Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    }

   public void advanceSearchStaff(){
          tableData = new Vector();
          this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));
          String gender = "%";
          String Firstname = "";
          String Lastname = "";
          String SearchKeyword = "%";


          if(!this.comGender.getSelectedItem().toString().equals("Both")) {
            gender = Function.set_gender(this.comGender.getSelectedItem().toString());
          } if(this.chkFirstname.isSelected()) {
              Firstname = this.txtSearch.getText()+"%";
          } if(this.chkLastname.isSelected()) {
              Lastname = this.txtSearch.getText()+"%";
          } if(!this.txtSearch.getText().equals("")) {
              SearchKeyword = this.txtSearch.getText();
          }
        try {
            Connection cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT StaffID,username,Firstname,Lastname,Phone,Email,Gender FROM tbl_Staff WHERE "+this.comSearch.getSelectedItem().toString()+" LIKE '%"+SearchKeyword+"%'"
                    + " AND Firstname LIKE '"+Firstname+"'"
                    + " AND Lastname LIKE '"+Lastname+"'"
                    + " AND Gender LIKE '"+gender+"'");
            if(!rs.first()) {
                JOptionPane.showMessageDialog(null, "Sorry, no result");
            }else {
                rs.first();
                Vector temp = new Vector();
                temp.add(rs.getString(1));
                temp.add(rs.getString(2));
                temp.add(rs.getString(3));
                temp.add(rs.getString(4));
                temp.add(rs.getString(5));
                temp.add(rs.getString(6));
                temp.add(Function.get_gender(rs.getString(7)));
                tableData.add(temp);
                while(rs.next()) {
                    temp = new Vector();
                    temp.add(rs.getString(1));
                    temp.add(rs.getString(2));
                    temp.add(rs.getString(3));
                    temp.add(rs.getString(4));
                    temp.add(rs.getString(5));
                    temp.add(rs.getString(6));
                    temp.add(Function.get_gender(rs.getString(7)));                          
                    tableData.add(temp);
                }
                this.tblStaffData.setModel(new DefaultTableModel(tableData, tableTitle));

            }
        } catch (SQLException ex) {
            Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        comRole = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblStaffData = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int vColIndex) {
                return false;
            }
        };
        jLabel2 = new javax.swing.JLabel();
        txtSearch = new javax.swing.JTextField();
        btnSearch = new javax.swing.JButton();
        pnAdvanceSearch = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        comGender = new javax.swing.JComboBox();
        chkLastname = new javax.swing.JCheckBox();
        chkFirstname = new javax.swing.JCheckBox();
        chkAdvanceSearch = new javax.swing.JCheckBox();
        btnAdd = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        comSearch = new javax.swing.JComboBox();

        setMaximumSize(new java.awt.Dimension(683, 452));

        jPanel1.setBackground(new java.awt.Color(227, 239, 255));
        jPanel1.setMaximumSize(new java.awt.Dimension(683, 440));
        jPanel1.setPreferredSize(new java.awt.Dimension(683, 440));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("View the list of :");

        comRole.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrator", "Staff" }));
        comRole.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comRoleItemStateChanged(evt);
            }
        });
        comRole.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                comRolePropertyChange(evt);
            }
        });

        tblStaffData.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblStaffData.setGridColor(new java.awt.Color(213, 213, 213));
        tblStaffData.setOpaque(false);
        tblStaffData.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblStaffDataMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblStaffData);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Search:");

        txtSearch.setToolTipText("");

        btnSearch.setText("Search");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        pnAdvanceSearch.setBorder(javax.swing.BorderFactory.createTitledBorder("Advance Search"));
        pnAdvanceSearch.setOpaque(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Gender:");

        comGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Both", "Male", "Female" }));

        chkLastname.setFont(new java.awt.Font("Tahoma", 1, 11));
        chkLastname.setText("Lastname");
        chkLastname.setOpaque(false);
        chkLastname.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chkLastnamePropertyChange(evt);
            }
        });

        chkFirstname.setFont(new java.awt.Font("Tahoma", 1, 11));
        chkFirstname.setText("Firstname");
        chkFirstname.setOpaque(false);
        chkFirstname.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkFirstnameActionPerformed(evt);
            }
        });
        chkFirstname.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chkFirstnamePropertyChange(evt);
            }
        });

        javax.swing.GroupLayout pnAdvanceSearchLayout = new javax.swing.GroupLayout(pnAdvanceSearch);
        pnAdvanceSearch.setLayout(pnAdvanceSearchLayout);
        pnAdvanceSearchLayout.setHorizontalGroup(
            pnAdvanceSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAdvanceSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comGender, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(17, 17, 17)
                .addComponent(chkFirstname)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkLastname)
                .addContainerGap(423, Short.MAX_VALUE))
        );
        pnAdvanceSearchLayout.setVerticalGroup(
            pnAdvanceSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAdvanceSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3)
                .addComponent(comGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(chkFirstname)
                .addComponent(chkLastname))
        );

        chkAdvanceSearch.setText("Advance Search");
        chkAdvanceSearch.setOpaque(false);
        chkAdvanceSearch.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chkAdvanceSearchPropertyChange(evt);
            }
        });

        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit Details");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        comSearch.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Username", "Email" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comRole, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSearch)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chkAdvanceSearch))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 790, Short.MAX_VALUE)
                            .addComponent(pnAdvanceSearch, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(296, 296, 296)
                        .addComponent(btnAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(comRole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(comSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(chkAdvanceSearch)
                        .addComponent(btnSearch)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnAdvanceSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnEdit)
                    .addComponent(btnDelete))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 421, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void comRolePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_comRolePropertyChange
       
    }//GEN-LAST:event_comRolePropertyChange

    private void chkAdvanceSearchPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chkAdvanceSearchPropertyChange
       if(this.chkAdvanceSearch.isSelected()) {
           this.pnAdvanceSearch.setVisible(true);
       } else {
           this.pnAdvanceSearch.setVisible(false);
       }
    }//GEN-LAST:event_chkAdvanceSearchPropertyChange

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        int selectedrow = this.tblStaffData.getSelectedRow();
         if(selectedrow >= 0) {
            if (role.equalsIgnoreCase("Administrator")) {
                try {
                     Vector temp = new Vector();
                     temp = ((Vector) tableData.get(selectedrow));
                    jdl_ChangeStaffInfo js = new jdl_ChangeStaffInfo(null, true, "Administrator", temp.get(1).toString(),true);
                    js.setVisible(true);
                    this.initTableAdmin();
                } catch (SQLException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ParseException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                } else {
                try {
                     Vector temp = new Vector();
                     temp = ((Vector) tableData.get(selectedrow));
                    jdl_ChangeStaffInfo js = new jdl_ChangeStaffInfo(null, true, "Staff", temp.get(1).toString(),true);
                    js.setVisible(true);
                    this.initTableStaff();
                } catch (SQLException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ParseException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "No user selected");
        }
    }//GEN-LAST:event_btnEditActionPerformed

    private void tblStaffDataMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblStaffDataMouseClicked
        if(evt.getClickCount() == 2) {
            int selectedrow = this.tblStaffData.getSelectedRow();
           
            if(selectedrow >= 0) {
                if(role.equalsIgnoreCase("Administrator")) {
                    try {
                        Vector temp = new Vector();
                        temp = ((Vector) tableData.get(selectedrow));
                        jdl_staffInfo si = new jdl_staffInfo(null, true,role, temp.get(1).toString());
                        si.setVisible(true);
                    } catch (ParseException ex) {
                        Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (SQLException ex) {
                        Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
                    }                  
                } else {
                    try {
                        Vector temp = new Vector();
                        temp = ((Vector) tableData.get(selectedrow));
                        jdl_staffInfo si = new jdl_staffInfo(null, true,role, temp.get(1).toString());
                        si.setVisible(true);
                    } catch (ParseException ex) {
                        Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (SQLException ex) {
                        Logger.getLogger(pnf_listStaff.class.getName()).log(Level.SEVERE, null, ex);
                    }      
                }

            }
        }
    }//GEN-LAST:event_tblStaffDataMouseClicked

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        int selectedrow = this.tblStaffData.getSelectedRow();
         if(selectedrow != -1) {
             if (role.equalsIgnoreCase("Administrator")) {
                  Vector temp = new Vector();
                   temp = ((Vector) tableData.get(selectedrow));
                     if(!temp.get(1).toString().equals(username)) {
                         User_function.delete_staff("tbl_Admin", temp.get(1).toString());
                         initTableAdmin();
                     }
                     else {
                       JOptionPane.showMessageDialog(null, "You can not delete yourself");
                     }                 
                } else {     
                     Vector temp = new Vector();
                     temp = ((Vector) tableData.get(selectedrow));
                    User_function.delete_staff("tbl_Staff", temp.get(1).toString());
                    initTableStaff();
            }
         } else {
            JOptionPane.showMessageDialog(null, "No user selected");
         }
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        jdl_addStaff as = new jdl_addStaff(null,true,role);
        as.setVisible(true);
        if(role.equals("Administrator")) {
            this.initTableAdmin();
        } else {
            this.initTableStaff();
        }
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        if(!this.chkAdvanceSearch.isSelected()) {
            if(role.equals("Administrator")) {
                this.search_admin();
            } else {
                this.search_staff();
            }
        } else {
             if(role.equals("Administrator")) {
                this.advanceSearchAdmin();
            } else {
                this.search_staff();
            }
        }
        
    }//GEN-LAST:event_btnSearchActionPerformed

    private void comRoleItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comRoleItemStateChanged
         if(this.comRole.getSelectedItem().equals("Administrator")) {
            initTableAdmin();
            role = "Administrator";
        } else {
            this.initTableStaff();
            role = "Staff";
        }
    }//GEN-LAST:event_comRoleItemStateChanged

    private void chkLastnamePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chkLastnamePropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_chkLastnamePropertyChange

    private void chkFirstnamePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chkFirstnamePropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_chkFirstnamePropertyChange

    private void chkFirstnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkFirstnameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_chkFirstnameActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnSearch;
    private javax.swing.JCheckBox chkAdvanceSearch;
    private javax.swing.JCheckBox chkFirstname;
    private javax.swing.JCheckBox chkLastname;
    private javax.swing.JComboBox comGender;
    private javax.swing.JComboBox comRole;
    private javax.swing.JComboBox comSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnAdvanceSearch;
    private javax.swing.JTable tblStaffData;
    private javax.swing.JTextField txtSearch;
    // End of variables declaration//GEN-END:variables

}
